package com.ccc.scala.base8_match

object Match05 {
  def main(args: Array[String]): Unit = {
    // 匹配列表
    for (list <-
           Array(
             List(0),
             List(1, 0),
             List(0, 0, 0),
             List(1, 0, 0),
             List(88))) {
      val result = list match {
        case List(0) => "0" //匹配List(0)
        case List(x, y) => x + "," + y //匹配有两个元素的List
        case List(0, _*) => "0 ..."
        case _ => "something else"
      }
      println(result)
      /*
          0
          1,0
          0 ...
          something else
          something else
       */
    }
    // val list: List[Int] = List(1, 2, 5, 6, 7) // 1-2-List(5, 6, 7)
    // val list: List[Int] = List(1, 2) // 1-2-List()
    val list: List[Int] = List(1) // something else

    list match {
      case first :: second :: rest => println(first + "-" + second + "-" + rest)
      case _ => println("something else")
    }


  }

}
